//
//  EViewController.m
//  页面之间传值
//
//  Created by MAC on 2018/8/27.
//  Copyright © 2018年 MAC. All rights reserved.
//

#import "EViewController.h"
//导入B页面头文件
#import "E-2-ViewController.h"

@interface EViewController ()
//声明全局UI指针
@property (nonatomic,strong) UILabel *label;
@property (nonatomic,strong) UIButton *btn;
@end

@implementation EViewController
//UILabel的懒加载
- (UILabel *)label
{
    if (_label == nil) {
        _label = [[UILabel alloc]initWithFrame:CGRectMake((self.view.frame.size.width-200)/2, 100, 200, 40)];
        _label.backgroundColor = [UIColor blackColor];
        _label.textColor = [UIColor whiteColor];
        _label.font = [UIFont systemFontOfSize:20];
    }
    return _label;
}
//UIButton的懒加载
- (UIButton *)btn
{
    if (_btn == nil) {
        _btn = [UIButton buttonWithType:UIButtonTypeCustom];
        _btn.backgroundColor = [UIColor redColor];
        _btn.frame = CGRectMake((self.view.frame.size.width-200)/2, _label.frame.origin.y+_label.frame.size.height+40, 200, 40);
        [_btn setTitle:@"跳转B页面" forState:UIControlStateNormal];
        [_btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        //点击事件
        [_btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    //把UI指针添加到View视图找那个
    [self.view addSubview:self.label];
    [self.view addSubview:self.btn];
    
}
//button点击事件 -- 跳转到B页面
- (void)btnClick
{
    //声明指针，并初始化
    E_2_ViewController *e_2_VC = [[E_2_ViewController alloc]init];
    //block传值 - 实现block - 接收来自B页面传值
    e_2_VC.block = ^(NSString *str) {
        self.label.text = str;
    };
    //模态进入B页面
    [self presentViewController:e_2_VC animated:YES completion:nil];
}
@end
